<?php

namespace app\api\controller\market;

use app\api\controller\Controller;
use app\Request;
use app\api\model\ad\Ad as AdModel;
use app\api\model\ad\AdCategory as AdCategoryModel;

/**
 * 广告控制器
 */
class Market extends Controller
{
    /**
     * 广告数据
     */
    public function index(Request $request)
    {
        $model = new AdModel;
        $type = $request->param('type','index');

        $user = $this->getUser();
        $Shopinfo = $this->getUserCache();

        $where['type'] = $type;
        $list = $model->getLists($where,6,$Shopinfo['shop']);


        if (!$list->isEmpty()) {
            $list = $list->toArray();

            foreach ($list as &$item) {
                $item = array_merge($item['image'], $item);
                unset($item['image']);
            }
        }
        return $this->renderSuccess('',compact('list'));
    }

    /**
     * 广告详情
     */
    public function detail($ad_id)
    {
        // 广告详情
        $detail = AdModel::detail($ad_id);
        $catgory = AdCategoryModel::getAll();
        return $this->renderSuccess('',compact('detail','catgory'));

    }
}
